package com.zlk.algorithm.huawei.leetcode.slidingWindow;

import org.junit.Test;

/**
 * @program: algorithm
 * @ClassName Code33_dismantlingAction
 * @description:LCR 167. 招式拆解 I
 *
 *
 * @author: slfang
 * @create: 2025-01-10 09:25
 * @Version 1.0
 **/
public class Code33_dismantlingAction {


    //请返回 arr 中最多可以出连续不重复的多少个招式。
    //输入：arr = "dbascDdad"
    //输出：6
    //解释：因为连续且最长的招式序列是 "dbascD" 或 "bascDd"，所以其长度为 6。
    public int dismantlingAction(String arr) {
        if("".equals(arr)||arr.length()==0){
            return 0;
        }
        int left = 0;
        int right = 1;
        int length = arr.length();
        int ans = 1;
        while (right<length){
            String rightStr = ""+arr.charAt(right);
            //区间字符是否包含新的字符
            while (left<right&&
                    arr.substring(left,right).contains(rightStr)){
                //不符合就缩小范围
                left++;
            }
            //符合就扩大范围，并且统计值
            ans = Math.max(arr.substring(left,right).length()+1,ans);
            right++;
        }
        return ans;
    }

    @Test
    public void test(){
        System.out.println(dismantlingAction("dbascDdad"));
    }
}
